#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <iomanip>
using namespace std;

class MyTime
{
public:
	int m_Hour;		//0<=hour<=23
	int m_Minute;	//0<=minute<=59
	int m_Second;	//0<=second<=59
	MyTime();
	MyTime(int hour, int minute, int second);
	void showTime_12();
	void showtime_24();
	void AddTime(int hour, int minute, int second);
	void MinusTime(int hour, int minute, int second);
};

MyTime::MyTime()
{
	m_Hour = 0;
	m_Minute = 0;
	m_Second = 0;
}

MyTime::MyTime(int hour, int minute, int second)
{
	m_Hour = hour;
	m_Minute = minute;
	m_Second = second;
}

void MyTime::showTime_12()
{
	if(m_Hour>=12)
		cout << setw(2) << setfill('0') << (m_Hour-12) << ":" 
		<< setw(2) << setfill('0') << m_Minute << ":" 
		<< setw(2) << setfill('0') << m_Second <<" PM" << endl;
	if(m_Hour<12)
		cout << setw(2) << setfill('0') << m_Hour << ":" 
		<< setw(2) << setfill('0') << m_Minute << ":" 
		<< setw(2) << setfill('0') << m_Second <<" AM" << endl;
}

void MyTime::showtime_24()
{
	cout << setw(2) << setfill('0') << m_Hour << ":"
	<< setw(2) << setfill('0') << m_Minute << ":"
	<< setw(2) << setfill('0') << m_Second << endl;
}

void MyTime::AddTime(int hour, int minute, int second)
{
	//加法函数
	m_Hour += hour;
	m_Minute += minute;
	m_Second += second;
	if (m_Second > 59)
	{
		m_Second -= 60;
		m_Minute += 1;
	}
	if (m_Minute > 59)
	{
		m_Minute -= 60;
		m_Hour += 1;
	}
	if (m_Hour > 23 || m_Hour < 0 || m_Minute>59 || m_Minute < 0 || m_Second>59 || m_Second < 0)
		return;
	showTime_12();
	showtime_24();
}

void MyTime::MinusTime(int hour, int minute, int second)
{
	//减法函数
	m_Hour -= hour;
	m_Minute -= minute;
	m_Second -= second;
	if (m_Second < 0)
	{
		m_Minute -= 1;
		m_Second += 60;
	}
	if (m_Minute < 0)
	{
		m_Hour -= 1;
		m_Minute += 60;
	}
	if (m_Hour > 23 || m_Hour < 0 || m_Minute>59 || m_Minute < 0 || m_Second>59 || m_Second < 0)
		return ;
	showTime_12();
	showtime_24();
}

int main()
{	
	MyTime t1;
	MyTime t2(6, 30, 20);
	t1.showTime_12();
	t1.showtime_24();
	t2.showTime_12();
	t2.showtime_24();
	int hour, minute, second;
	cin >> hour >> minute >> second;
	
	if (hour > 23 || hour < 0 || minute>59 || minute < 0 || second>59 || second < 0)
		return 0;
	
	
	int w_hour, w_minute, w_second;
	cin >> w_hour >> w_minute >> w_second;
	if (w_hour > 23 || w_hour < 0 || w_minute>59 || w_minute < 0 || w_second>59 || w_second < 0)
		return 0;
	
	t1.m_Hour = hour;
	t1.m_Minute = minute;
	t1.m_Second = second;
	t1.AddTime(w_hour, w_minute, w_second);
	t2.MinusTime(w_hour, w_minute, w_second);
	return 0;
}
